home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 187_01 / fdate.c < prev    next >
C/C++ Source or Header  |  1986-02-19  |  2KB  |  65 lines

  1. /*@*****************************************************/
  2. /*@                                                    */
  3. /*@ fdate - get the file date/time stamp and return    */
  4. /*@     it in string form as "YY-MM-DD HH:MM:SS ".     */ 
  5. /*@                                                    */
  6. /*@   Usage:   fdate(fp, buf, fn);                     */
  7. /*@       where fp is a file "handle".                 */
  8. /*@            buf is a buffer to receive the string.  */
  9. /*@            fn is the filename (used in error msg). */
  10. /*@                                                    */
  11. /*@*****************************************************/
  12.  
  13.  
  14. extern unsigned _rax, _rbx, _rcx, _rdx, _rsi, _rdi, _res, _rds;
  15. extern char _carryf, _zerof;
  16.  
  17. char *fdate(fp, buf, fn)
  18. int fp;                /* file pointer */
  19. char *buf;            /* buffer for output */
  20. char *fn;            /* filename (for error message) */
  21. /*
  22.  * Return MM-DD-YY HH:MM:SS for last update for file "fp".
  23.  */
  24. {
  25.     int _doint(), mon, day, year, hour, min, sec;
  26.     char *z_fill(), *itoa();
  27.  
  28.     buf[0] = 0x00;    /* clear output area */
  29.     _rax = 0x5700;    /* get date/time DOS function */
  30.     _rbx = fp;        /* file handle */
  31.     _rcx = 0;        /* returns time here */
  32.     _rdx = 0;        /* returns date here */
  33.     _doint(0x21);    /* call DOS */
  34.  
  35.     if (_carryf) {        /* error */
  36.         puts("Unable to get date/time stamp for ", fn);
  37.         return buf;        /* buf is empty at this time */
  38.     }
  39.  
  40.     mon = (_rdx >> 5) & 0x0f;
  41.     day =  _rdx & 0x1f;
  42.     year = ((_rdx >> 9) & 0x7f) + 80;
  43.  
  44.     hour = (_rcx >> 11);
  45.     min  = (_rcx >> 5) & 0x3f;
  46.     sec =  (_rcx & 0x1f);
  47.  
  48.     z_fill(itoa(year, buf), 2);
  49.     buf[2] = '-';
  50.     z_fill(itoa(mon,&buf[3]), 2);
  51.     buf[5] = '-';
  52.     z_fill(itoa(day,&buf[6]), 2);
  53.     buf[8] = ' ';
  54.     z_fill(itoa(hour,&buf[9]), 2);
  55.     buf[11] = ':';
  56.     z_fill(itoa(min,&buf[12]), 2);
  57.     buf[14] = ':';
  58.     z_fill(itoa(sec,&buf[15]), 2);
  59.     buf[17] = ' ';
  60.     buf[18] = 0x00;            /* end of string */
  61.  
  62.     return buf;        /* allow stacking of functions */
  63. }
  64.  
  65.